home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / virus / BBBF109p.lha / Programmers / CheckDrive.c < prev    next >
C/C++ Source or Header  |  1994-03-16  |  5KB  |  147 lines

  1. /* CheckDrive 1.6 © Johan Eliasson 1992             *
  2.  * To be compiled with SAS C (any version, I think) *
  3.  * > lc -L CheckDrive.c will do.                    */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h> 
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <devices/trackdisk.h>
  10.  
  11. #include <BBBF.h>
  12. #include <BBBF_pragmas.h>
  13. #include <BBBF_protos.h>
  14.  
  15. #include "CheckDrive_protos.h"
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19.  
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/dos_pragmas.h>
  22.  
  23. #define VERNO   "1.6"
  24. #define VERDATE "(25.04.93)"
  25.  
  26. #define HELLO   "CheckDrive "VERNO" © Johan Eliasson 1992,1993\n"
  27. #define USAGE   "Usage: CheckDrive <drive>\ndrive = the drive you want to check\n"
  28.  
  29. UBYTE *VersionString = "$VER: CheckDrive "VERNO" "VERDATE;
  30.  
  31. extern struct DOSBase *DOSBase;
  32.  
  33. struct Library *BootblockBase = NULL;
  34.  
  35. struct Bootblock *BB;
  36.  
  37. ULONG chip boot[256];   /* Must be in CHIP if OS 1.3  */
  38. ULONG      drive;       /* unit number of drive       */
  39. USHORT     virus;       /* amount of recognized virii */
  40. char       string[80];  /* general string for output  */
  41. char       version[30]; /* brainfile version string   */
  42. long       retcode;     /* for CheckBoot()            */
  43. long       readerror;
  44.  
  45. /* ****************************** main() ****************** */
  46.  
  47. void main(int argc,char *argv[])
  48. {
  49.   if ((argc == 1) || (argv[1][0] == '?'))
  50.     die(USAGE);
  51.  
  52.   out(HELLO);
  53.  
  54.   /* ***************** Open Bootblock.library ************* */
  55.  
  56.   if (!(BootblockBase = (struct Library *) OpenLibrary("Bootblock.library",1)))
  57.     die("\nCheckDrive needs the bootblock.library v1.0+ !");
  58.  
  59.   /* ****************** Read brainfile ******************* */
  60.  
  61.   out("Reading Bootblock.brainfile...");
  62.  
  63.   readerror = ReadBBBF("L:Bootblock.brainfile");
  64.  
  65.   if (readerror == ERROR_OBJECT_NOT_FOUND) readerror = ReadBBBF("Bootblock.brainfile");
  66.  
  67.   /* ****************** Check result************************** */
  68.  
  69.   switch (readerror)
  70.   {
  71.     case BBBF_LOADED            : out("Ok!\n\n"); break;
  72.     case BBBF_ALREADY_LOADED    : out("\n\nThe brainfile was already loaded!\n"); break;
  73.  
  74.     case BBBF_NOT_BBBF          : die("\n\nIt is not a Bootblock.brainfile!\n");
  75.     case BBBF_CHECKSUM_ERROR    : die("\n\nThe Bootblock.brainfile is corrupted!\n");
  76.     case BBBF_OUT_OF_MEMORY     : die("\n\nNo memory for brainfile!\n");
  77.     case ERROR_OBJECT_NOT_FOUND : die("\n\nCan't find the Bootblock.brainfile!\n");
  78.     default                     : die("\n\nSomething went wrong...\n");
  79.   };
  80.  
  81.   /* ***************** Get additional info **************** */
  82.  
  83.   if (GetBBBFInfo(&virus,version) == BBBF_NOT_LOADED)
  84.     die("The brainfile is not loaded!");
  85.  
  86.   /* ************************ Output info ********************** */
  87.  
  88.   sprintf(string,"Brainfile version %s.\nKnows %d viruses.\n\n",version,virus);
  89.   out(string);
  90.  
  91.   /* ************************ Prepare for boot-read ***************** */
  92.  
  93.   if ((toupper(argv[1][0]) == 'D') && (toupper(argv[1][1]) == 'F'))
  94.     drive = atol((char *) &argv[1][2]); /* CheckDrive dfx: */
  95.   else drive = atol(argv[1]);           /* CheckDrive x    */
  96.  
  97.   /* ********************** Read boot ***************************** */
  98.  
  99.   if (readerror = ReadBoot(drive,(char *) boot))
  100.     tderror(readerror);
  101.  
  102.   /* ********************** Check boot ************************** */
  103.  
  104.   BB = (struct Bootblock *) CheckBoot(boot,&retcode);
  105.  
  106.   switch (retcode)
  107.   {
  108.     case BBBF_NOT_LOADED : die("Brainfile is not loaded!");
  109.     case BOOT_VIRUS      : sprintf(string,"WARNING! The disk in DF%d: is infected with the \'%s\' virus!\n",drive,BB->bootname);
  110.                            die(string);
  111.     case BOOT_UNKNOWN    : sprintf(string,"The disk in DF%d: is not infected with any known bootvirus!\n",drive);
  112.                            die(string);
  113.     case BOOT_NOT_BOOT   : sprintf(string,"The disk in DF%d: is not bootable!\n");
  114.                            die(string);
  115.   }
  116.  
  117.   die(USAGE);
  118. }
  119.  
  120. void tderror(long error)
  121. {
  122.   switch (error)
  123.   {
  124.     case TDERR_WriteProt    : die("The disk is writeprotected!\n");
  125.     case TDERR_DiskChanged  : die("There's no disk in the drive!\n");
  126.     case TDERR_BadDriveType : die("That drive is not available!\n");
  127.     case TDERR_BadUnitNum   : die("There's no drive with that number!\n");
  128.     case TDERR_DriveInUse   : die("The drive is busy!\n");
  129.   }
  130.  
  131.   Fault(error,"Error",string,81);
  132.   die(string);
  133. }
  134.  
  135. void out(char *string)
  136. {
  137.   Write(Output(),string,strlen(string));
  138. }
  139.  
  140. void die(char *message)
  141. {
  142.   out(message);
  143.   if (BootblockBase) CloseLibrary(BootblockBase);
  144.   exit(0);
  145. }
  146.  
  147.